package org.uim.cricket.analyzer.parsers.match.impl;

import org.uim.cricket.analyzer.parsers.match.MatchSpanParsable;
import org.uim.cricket.entities.match.MatchSpanTypes;
import org.uim.cricket.entities.match.MatchSpans;
import org.uim.cricket.util.MyStringUtils;

public class DefaultMatchSpanParser implements MatchSpanParsable {

	@Override
	public MatchSpans getSpanData(String source) {
		if (source == null) return null;
		MatchSpans spans = new MatchSpans();
		
		source = MyStringUtils.replaceAll(source, "", "\\(", "\\)");
		int pos = source.indexOf('-');
		if (pos < 0) return null;
		
		
		spans.setSpans(Integer.parseInt(source.substring(0, pos)));
		source = source.substring(pos + 1);
		if (source.startsWith("day")) {
			spans.setSpanType(MatchSpanTypes.DAYS);
		} else if (source.startsWith("over")) {
			spans.setSpanType(MatchSpanTypes.OVERS);
		}
		
		return spans;
	}

}
